/**
 * localStroage封装
 */
import config from '../config';

const namespace = config.namespace || 'aaa';
function getStorage() {
  const temp = window.localStorage.getItem(namespace) || '{}';
  return JSON.parse(temp);
}
export default {
  getItem(key) {
    const obj = getStorage();
    return obj[key];
  },
  setItem(key, value) {
    const obj = getStorage();
    obj[key] = value;
    const temp = JSON.stringify(obj);
    window.localStorage.setItem(namespace, temp);
  },

  clearItem(key) {
    const obj = getStorage();
    delete obj[key];
    const temp = JSON.stringify(obj);
    window.localStorage.setItem(namespace, temp);
  },
  clearAll() {
    window.localStorage.clear();
  },
};
